<?php

require_once 'LikeMVC/Loader/AutoLoader/Interface.php';

/**
 * 
 * Act as a proxy for the concrete autoloader
 * using Strategy pattern
 * @author griever
 *
 */
class LikeMVC_Loader_Autoloader implements LikeMVC_Loader_AutoLoader_Interface {

	private static $instance;
	
	private $autoLoader;
	
	public static function getInstance()	{
		if (self::$instance == null)	{
			self::$instance = new LikeMVC_Loader_Autoloader();
		}
		return self::$instance;
	}
	
	private function __construct()	{
		$this->defaultAutoLoader();
	}
	
	/**
	 * Use the default auto loader LikeMVC_Loader_AutoLoader_Standard
	 */
	public function defaultAutoLoader()	{
		require_once 'LikeMVC/Loader/AutoLoader/Standard.php';
		$this->autoLoader = new LikeMVC_Loader_AutoLoader_Standard();
		return $this->autoLoader;
	}
	
	/**
	 * Change the current auto loader
	 * @param unknown_type $autoLoader
	 */
	public function setAutoLoader($autoLoader)	{
		require_once 'LikeMVC/Loader/AutoLoader/Interface.php';
		if ($autoLoader instanceof LikeMVC_Loader_AutoLoader_Interface)	{
			$this->autoLoader = $autoLoader;
		}
	}
	
	/**
	 * Autoload a class
	 * @see LikeMVC_Loader_AutoLoader_Interface::autoload()
	 */
	public function autoload($class)	{
		if ($this->autoLoader != null)	{
			return $this->autoLoader->autoload($class);
		}
		return false;
	}
}

?>